#ifndef MYDATA_H
#define MYDATA_H

#include <QObject>
#include<QColor>
class Round{
public:
    Round(int x,int y,int w,int h, int dir,QColor c);
    int x;
    int y;
    int w;
    int h;
    int  dir; //方向0-up，1-down，2-left，3-right
    QColor color;
};
class Car{
public:
    Car(int x,int y,int roundIndex, int roundPos, int id);

    int x;
    int y;
    int roundIndex;
    int roundPos;  //道路位置
    int id;     //序号
};

class SignalLamp{
public:
    SignalLamp(QColor c, int group, int roundIndex);
    QColor color;
    int group;  //分组
    int roundIndex;
};

class Junction{
public:
    void addLamp(SignalLamp *lamp);
    int lampCount();
    int lampGroupCount();
    SignalLamp *getLamp(int lampIndex);
protected:
    QList<SignalLamp *>lampList;
};

class MyData : public QObject
{
    Q_OBJECT
protected:
    explicit MyData(QObject *parent = nullptr);
public:
    static MyData* getObject();
    int roundCount();
    Round *getRound(int roundIndex);
    int carCount();
    Car *getCar(int carIndex);

    int junctionCount();
    Junction *getJunction(int junctionIndex);

    void updateCarPos(int carIndex,int roundIndex,int roundPos);
    void updateRound();
    void updatenewLampColorSlot(int junctionId, int lampId,int color);

protected:
    void initRoundList();
    void initCarList();
    void initJunctionList();

    static MyData* obj;
    QList<Round *>roundList;
    QList<Car *>carList;
    QList<Junction *>junctionList;

};

#endif // MYDATA_H
